import 'package:app/pages/reward_modules/RewardModel.dart';
import 'package:app/pages/reward_modules/reward_top_dialog_page.dart';
import 'package:app/services/address.dart';
import 'package:app/services/dio_manager.dart';
import 'package:bot_toast/bot_toast.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:get/get.dart';

class RewardController extends GetxController{



  var searchTextEditingController = TextEditingController();

  var easyRefreshController = EasyRefreshController();

  int page = 1;
  List dataArr = [];
  var status;

  var isTopShow = false;

  var replyType = '未执行';

  /// 点击的弹框
  topClick() async {
    isTopShow = true;

    print(replyType);
    var a;
    if (replyType == '未执行') {
      a = 0;
    }
    if (replyType == '已执行') {
      a = 1;
    }

    var data =
    await Get.dialog(RewardTopDialogPage(a), barrierColor: Colors.transparent);
    if (data != null) {
      print(data);
      isTopShow = data['isShow'];
      replyType = data['text'];
      status = data['reply_type'];
      page = 1;
      requestData(state: status);
    }
    update();
  }


  onRefresh()async{
    page = 1 ;
    requestData();
  }
  onLoad()async{
    page++;
    requestData();
  }


  requestData({var search,var state})async{
    var params = {
      'page':page,
      'limit':10,
      'status':state, //状态，未执行，已执行
    };
    var json = await DioManager().kkRequest(Address.myRewardList,params: params,method: 'get');
    RewardModel model = RewardModel.fromJson(json);

    if(page == 1){
      easyRefreshController.resetLoadState();
      dataArr.clear();
    }
    if(model.data!=null){
      dataArr.addAll(model.data!);
    }else if(model.data == null){
      BotToast.showText(text: '暂无更多');
      easyRefreshController.finishLoad(noMore: true);
    }
    update();
  }

  @override
  void onInit() {
    // TODO: implement onInit
    super.onInit();
    requestData(state: status);
  }
}